﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Interfaces;

namespace People.Controllers
{
    public class NewsController : Controller
    {
        private readonly INewsBll _newsBll;

        public NewsController(INewsBll newsBll)
        {
            _newsBll = newsBll;
        }

        //
        // GET: /News/

        public ActionResult IndexNews()
        {
            return PartialView("IndexNews", _newsBll.ReadSomeNews());
        }

        [HttpGet]
        public ActionResult AddNews()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AddNews(string title, string content)
        {
            var date = DateTime.Now;
            if (ModelState.IsValid && _newsBll.Create(title, content, date))
            {
                return Redirect("/Home/Index");
            }
            return View();
        }

        public ActionResult AllNews()
        {
            return View("AllNews", _newsBll.ReadAll());
        }

        public ActionResult ViewNews (Guid id)
        {
            var t = _newsBll.Read(id);
            return View(t);
        }
    }
}
